<%-- 
    Document   : admin_login
    Created on : Feb 22, 2012, 3:30:07 PM
    Author     : Ervin  James
--%>

<%@page import="ContentManagers.RoleManagers.AuthenticationManager"%>
<%@page import="ContentManagers.Servlets.ServletAdminLogin"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<% //employ temporary session management here
        try{
          
                if(session.getAttribute("username") != null && (session.getAttribute("username").equals("xxxxdefaultxxxx") == false))
                {   //System.out.print(session.getAttribute("username").toString());
                    new AuthenticationManager().redirectToProperIndex(0, request, response); 
                    
                }
                
                else{
        %>

<!DOCTYPE html>
<html>
     <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <link rel="stylesheet" type="text/css" href="css/admin_int.css" />
            </head>
            <body>
            <script type='text/javascript' src='Javascript/adminjs.js'></script>
            
                <center><br><Br><br><br><br><br><br> 
                    <div class="login_box" id ="managing_login">
                            <img src="images/foo_admin.png"> 
                        <% //This section is for the simple login lockout mechanism. 

                            try{

                            ServletAdminLogin.resetIfTimeOut(request); 

                            if(session.getAttribute("formLockout").toString().equals("off"))
                                {  //login form will appear if attemptCount < 5
                                    System.out.print(session.getAttribute("formLockout"));
                                %>

                                <form name ="admin_login" method="post" onsubmit="" action="../ServletAdminLogin">
                                    <br>Username:
                                                <br><input class="inputbox" id="adminUsernameField" type="text" value="" name="username" autocomplete ="off" onfocus="clearInitial(this, 'Username')" onBlur="checkAdminLogin()"/>
                                    <br>Password:
                                                <br><input class="inputbox" id="adminPasswordField" type="password" value="" name="password" autocomplete ="off" onfocus="clearInitial(this, 'Password')" onBlur="checkAdminLogin()"/>
                                    <br><input type="submit" id="adminSubmitLogin" name="SubmitAdminLogin" value="Login"/>
                                    <br>
                                    <%
                                    if(session.getAttribute("errorMessage")!=null)
                                    {
                                        if(session.getAttribute("errorMessage").equals("invalid"))
                                            out.println("Invalid username or password.");

                                        session.removeAttribute("errorMessage");
                                    }
                                    %>

                            </form>
                            <% }
                        else 
                            { //display this div if attemptCount = 5

                            %>
                                <div id="login_div">
                                    <br><br><br>Login lockout for 5 minutes. <br><br><br><br>
                                </div>

                        <% } %>
                                                <Br>
                            <a href="../index.jsp"> Go Back.</a>


                    </div>
                </center>             
                </body>
    <%  }
    catch(Exception e)
        {   session.setAttribute("formLockout", "off");
            response.sendRedirect("admin_login.jsp");
        }
        }}
                                               
    catch(Exception e)
        {   session = request.getSession();
            session.setAttribute("username", "xxxxdefaultxxxx");
            session.setAttribute("sessionID", "xxxxdefaultxxxx");
                
            response.sendRedirect("../index.jsp");
            
        } 
    %>
        
</html>
